import gtk,gobject
import WindowTemplate

class ThreadSafeDialog(WindowTemplate.WindowTemplate):    
    def __init__(self,controller,title,message,callback,*args):
        WindowTemplate.WindowTemplate.__init__(self,controller)
        self.set_title(title)
        self.message = message
        self.callback = callback
        self.create_window()
        self.btn_ok.connect('clicked',self.do_callback,args)
        self.btn_cancel.connect('clicked',self.close)
        
    def create_window(self):
        global_vbox = gtk.VBox()
        lbl_message = gtk.Label(self.message)
        self.btn_ok = gtk.Button(None,gtk.STOCK_OK)
        self.btn_cancel = gtk.Button(None,gtk.STOCK_CANCEL)
        global_vbox.pack_start(lbl_message,False)
        global_vbox.pack_start(self.build_hbox((self.btn_ok,self.btn_cancel)),False)
        self.add(global_vbox)
        self.show_all()
    
    def do_callback(self,btn,args):
        gobject.idle_add(self.callback,args)
        self.close()

class InfoDialog:
    def __init__(self,title,message,parent=None):
        self.dialog = gtk.Dialog(title,parent, 
                        gtk.DIALOG_MODAL | gtk.DIALOG_DESTROY_WITH_PARENT,
                        (gtk.STOCK_OK, gtk.RESPONSE_ACCEPT))
        
        content_area = self.dialog.get_content_area()
        content_area.pack_start(gtk.Label(message))
        
        self.dialog.show_all()
    
    def run(self):
        self.res = self.dialog.run()
        self.dialog.destroy()
        return self.res
    
class Dialog:
    def __init__(self,title,message,parent=None):
        self.dialog = gtk.Dialog(title,parent, 
                        gtk.DIALOG_MODAL | gtk.DIALOG_DESTROY_WITH_PARENT,
                        (gtk.STOCK_CANCEL, gtk.RESPONSE_REJECT,
                        gtk.STOCK_OK, gtk.RESPONSE_ACCEPT))
        
        content_area = self.dialog.get_content_area()
        content_area.pack_start(gtk.Label(message))
        
        self.dialog.show_all()
    
    def run(self):
        self.res = self.dialog.run()
        self.dialog.destroy()
        return self.res
       
class InputDialog:
    def __init__(self,title,message,parent=None):
        self.dialog = gtk.Dialog(title,parent, 
                        gtk.DIALOG_MODAL | gtk.DIALOG_DESTROY_WITH_PARENT,
                        (gtk.STOCK_CANCEL, gtk.RESPONSE_REJECT,
                        gtk.STOCK_OK, gtk.RESPONSE_ACCEPT))
        
        content_area = self.dialog.get_content_area()
        content_area.pack_start(gtk.Label(message))
        content_area.pack_start(gtk.Entry())
        self.dialog.show_all()
    
    def run(self):
        self.res = self.dialog.run()
        self.dialog.destroy()
        return res,self.tb.get_text()

if __name__ == '__main__':
    prout = InfoDialog("prout","prout")
    print prout.run()
    